package com.cw.jeeyt.controller.system;

import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.cw.jeeyt.common.utils.UploadUtils4;
import com.cw.jeeyt.common.web.BaseController;

@Controller
@RequestMapping("/file")
public class FileController extends BaseController {
    /**
     * 根据操作类型保存附件信息数据
     *
     */
    @ResponseBody
    @RequestMapping(value = "/uploadFiles", method = RequestMethod.POST)
    public String uploadFiles(HttpServletRequest request) {
        Calendar calendar = Calendar.getInstance();
        List<UploadUtils4.UploadResult> filePathList = new ArrayList<>();
        String filePath = "c:/temp";
        filePath = filePath + File.separatorChar + calendar.get(Calendar.YEAR) + calendar.get(Calendar.MONTH);
        try {
            filePathList = UploadUtils4.getInstance().uploadFile(filePath,request);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        if (filePathList.size() == 0) {
            //return "系统错误";
        }
        return JSONArray.toJSONString(filePathList);
    }
}
